//规定：级别越高，管负责理的功能权限越大。

package bupt.party.online.util;

import java.sql.Timestamp;
import java.util.Calendar;

public class BuptPartyConfig {
	
	//定义每年的学时要求 
	public static final int EVERY_YEAR_LEARN_TIME = 16; //16小时
	
	//定义每年的统计学习的开始时间 
//	public static final  String START_MONTH_DATE = "-09-01 00:00:00";//大于‘起始点’
	
	public static final  String START_MONTH_DATE = "-01-01 00:00:00";//大于‘起始点’
	
	//定义每年的统计学习的截止 
//	public static final  String END_MONTH_DATE = "-06-30 00:00:00";//小于等于‘终点’
	
	public static final  String END_MONTH_DATE = "-12-31 23:59:59";//小于等于‘终点’

	
	
	//计算参与率的方法
	public static double  calculateParticipateRate(double[] learnTime,int studentCount){
		double participateRate = 0.0;
		double SUM = 0.0;
		for(int i=0;i<learnTime.length;i++){
			if(learnTime[i]<=BuptPartyConfig.EVERY_YEAR_LEARN_TIME)
				SUM+=learnTime[i];
			else 
				SUM+=BuptPartyConfig.EVERY_YEAR_LEARN_TIME;
		}
		if(SUM==0.0){
			return participateRate;
		}else{
			participateRate = SUM/(studentCount*BuptPartyConfig.EVERY_YEAR_LEARN_TIME);
			//精确到小数点后三位。例如：16.667%
			double particpate = ((int)(participateRate*100000))/1000.0;
			return particpate;
		}
	}
	
	
	
	
	
	
	
	
	
	public static void main(String[] args) throws Exception {
		//测试计算参与率
		double[]  array = new  double[]{1.0,2,0,3.0,4.0,5.0,17.0};
		int studentCount = 6;
		double  participateRate = BuptPartyConfig.calculateParticipateRate(array, studentCount);

		System.out.println("participateRate="+participateRate+"%");
		
		
		
//		String str = "2011-09-18";
//		System.out.println(DateUtil.str2Timestamp(str));
//		
//		System.out.println(DateUtil.Date2DefaultStr(Calendar.getInstance().getTime()));
	}
	
	
	public static double timeDifference(Timestamp t1,Timestamp t2){
		long timeDifference_second = (long) ((t2.getTime()-t1.getTime())/1000.0);
	   
	    long timeDifference_minutes = (long) (timeDifference_second/60.0);
	    
	    //将分钟转化为小时
	    Double dl = Double.parseDouble(String.valueOf(timeDifference_minutes))/60.0;
	    
	    double timeDifference_hours = ((int)(dl*1000))/1000.0; //timeDifference_hours精确到小数点后三位
		
		return timeDifference_hours;
	}
	
	
	

	//截取字符串的函数，超长表单内容，截断保存到数据库中
	public static String subString(String str, int toCount)
    {
      int reInt = 0;
      String reStr = "";
      if (str == null)
        return "";
      char[] tempChar = str.toCharArray();
      for (int kk = 0; (kk < tempChar.length && toCount > reInt); kk++) {
        String s1 = str.valueOf(tempChar[kk]);
        byte[] b = s1.getBytes();
        reInt += b.length;
        reStr += tempChar[kk];
      }
	      
      return reStr;
	} 
}
